package com.test2015.Swing.popup.thumbnail;

import java.awt.Container;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JComponent;
import javax.swing.SwingUtilities;

public class ThumbnailMouseListener extends MouseAdapter{

	private static final Object JComponent = null;
	private Thumbnail thumbnail = null; 
	
	public ThumbnailMouseListener(Thumbnail thumbnail){
		this.thumbnail = thumbnail;
	}
	
	@Override
	public void mouseEntered(MouseEvent mouseevent) {
		Object source = mouseevent.getSource();
		
		if(source instanceof JComponent){
			Point point = mouseevent.getPoint();
			JComponent tmp = (JComponent)source;
			Container parent = tmp.getParent();
			SwingUtilities.convertPointToScreen(point,tmp);
			
			thumbnail.showThumbnail(parent, point.x, point.y);
		}
		
	}

	@Override
	public void mouseExited(MouseEvent mouseevent) {
		thumbnail.hideThumbnail();
	}
	
	
}
